<template>
  <el-form label-position="right" label-width="80px" :model="formLabelAlign">
    <el-form-item label="下单时间">
      <el-input v-model="formLabelAlign.startTime" :disabled="true"> </el-input>
    </el-form-item>
    <el-form-item label="完成时间">
      <el-input v-model="formLabelAlign.endTime" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="客户">
      <el-select v-model="formLabelAlign.customersId" placeholder="请选择">
        <el-option
          v-for="item in allClients"
          :key="item._id"
          :label="item.name"
          :value="item._id"
        >
        </el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="产品">
      <el-select v-model="formLabelAlign.productsId" placeholder="请选择">
        <el-option
          v-for="item in all"
          :key="item._id"
          :label="item.name"
          :value="item._id"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-button type="primary" plain @click="ordersAdd">新增订单</el-button>
  </el-form>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions} = createNamespacedHelpers("adminsOrders");
const { mapActions:mapActionsCustomersId ,mapState:mapStateData} = createNamespacedHelpers("adminCustomers");
const { mapActions:mapActionsProductsId ,mapState:mapStateProductsData} = createNamespacedHelpers("productsManages");
export default {
   mounted() {
    this.tm();
    this.getCustomersAllId();
    this.getProductsall();
  },
  data() {
    
    return {
      formLabelAlign: {
        startTime:this.moment().format('YYYY-MM-DD H:mm:ss a'),
        // state:"",
        // termination: "",
        endTime:this.moment().format('YYYY-MM-DD H:mm:ss a'),
        salesId:localStorage.getItem("_id") ,
        customersId:"",
        productsId:"",
      },
      
    };
  },
  computed: {
    ...mapStateData(["allClients"]),
    ...mapStateProductsData(["all"]),
  },
methods:{
    tm(){
       setInterval(()=>{this.formLabelAlign.endTime=this.moment().format('YYYY-MM-DD H:mm:ss a')},1000);
     
     
    },
      ...mapActionsCustomersId(["getCustomersAllId"]),
      ...mapActions(["postOrdersAdd"]),
      ...mapActionsProductsId(["getProductsall"]),
    async  ordersAdd(){
const       data=await this.postOrdersAdd(this.formLabelAlign)
if (data.data.code) {
  this.$message('添加成功');
    this.formLabelAlign.customersId="";
    this.formLabelAlign.productsId=""
} else {
  this.$message('添加失败');
}}}
}
</script>

<style>
</style>